<?php

require_once(dirname(__FILE__) . '/appconf.php');

class ImageUp extends Site {

    function setup() {
        $this->run_modes('ImageUp');
        $this->start_mode('ImageUp');
        parent::setup();
    }

    function cgiapp_prerun($rm = '') {
        parent::cgiapp_prerun();
    }

    function action_ImageUp() {
        header("Content-Type: text/html; charset=utf-8");

        //上传图片框中的描述表单名称，
        //$title = htmlspecialchars($this->get_q('pictitle'));

        $root = $this->param('WWW');
        $up = uploadfiles($root . '/upload/ueidtor', "upfile");
        $url = str_replace($root, "", $up[0]['path']);
        /*if ($up) {
            $result = $up[0];

            
            /**
             * 向浏览器返回数据json数据
             * {
             *   'url'      :'a.jpg',   //保存后的文件路径
             *   'title'    :'hello',   //文件描述，对图片来说在前端会添加到title属性上
             *   'original' :'b.jpg',   //原始文件名
             *   'state'    :'SUCCESS'  //上传状态，成功时返回SUCCESS,其他任何值将原样返回至图片上传框中
             * }
             *
            echo "{'url':'" . $url . "','title':'" . $title . "','original':'" . $result['filename'] . "','state':'SUCCESS'}";
        } else {
            echo "{'url':'" . $url . "','title':'" . $title . "','original':'" . $result['filename'] . "','state':'FALSE'}";
        }
        */
        echo json_encode(array('error' => 0, 'url' => $url));
    }

}

$webapp = new ImageUp();
$webapp->run();






